package com.authentications.service;

import com.authentications.filter.WholeRequestFilter;
import com.authentications.filter.info.UrlPathWhiteValue;
import com.authentications.filter.login.DefaultLoginController;
import com.authentications.filter.login.incomplete.GeneralLogin;
import com.authentications.strategy.OpenFilter;
import com.authentications.utils.SpringContextUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName AuthenticationUniversaServiceAutoConfiguration
 * @Author xiezhuocai
 * @Description filter 认证模式
 * @Date 2021/12/15 9:22
 */
@Configuration
@ConditionalOnWebApplication
@EnableConfigurationProperties(UrlPathWhiteValue.class)
@ConditionalOnBean(OpenFilter.class)
public class AuthenticationUniversaServiceAutoConfiguration {

    @Autowired
    private UrlPathWhiteValue whiteValue;

    @Bean
    public SpringContextUtils springContextUtils() {
        return new SpringContextUtils();
    }

    @Bean
    public WholeRequestFilter wholeRequestFilter(){
        return new WholeRequestFilter(whiteValue);
    }

    @Bean
    @ConditionalOnBean(GeneralLogin.class)
    public DefaultLoginController defaultLoginController(){
        return new DefaultLoginController();
    }

}
